package designPattern.singleton;

public class ThreadSafeSingleton {

	private static int createTimes = 0;
	private static ThreadSafeSingleton instance;
	
	private int id ;
	
	private ThreadSafeSingleton() throws Exception{
		
          String test="";
          for(int i = 0; i < 1000; i++){
        	  test+=i;
          }
          createTimes++;
			System.out.println(ThreadSafeSingleton.class.getName()+" create instance:"+createTimes+" times");
	}
	
	public synchronized static ThreadSafeSingleton getInstance() throws Exception{
		
		if(instance == null){
			
			instance =  new ThreadSafeSingleton();
		
		}
		
		return instance;
	}
}
